package service

import (
	"github.com/pkg/errors"
	v1 "k8s.io/api/core/v1"
	"time"
)

type ServiceType string

const (
	ClusterIP ServiceType = "ClusterIP"
	NodePort  ServiceType = "NodePort"
)

var ServiceExists = errors.New("Service is exists")
var ServiceNotExists = errors.New("Service is not exists")

type ReqBase struct {
	Name      string `json:"name" form:"name"`
	Namespace string `json:"namespace" form:"namespace"`
}

type CreateReq struct {
	ReqBase  `json:",inline"`
	Type     ServiceType       `json:"type" form:"type"`
	Selector map[string]string `json:"selector" form:"selector"`
	Ports    []v1.ServicePort  `json:"ports" form:"ports"`
}

type DeleteReq struct {
	ReqBase `json:",inline"`
}

type ListReq struct {
	ReqBase `json:",inline"`
}

type CreateResp struct {
	Name    string      `json:"name"`
	IsOk    bool        `json:"is_ok"`
	Service *v1.Service `json:"info"`
}

type Service struct {
	ServiceName string      `json:"service_name" bson:"service_name"`
	Namespace   string      `json:"namespace" bson:"namespace"`
	CreateTime  time.Time   `json:"create_time" bson:"create_time"`
	Deployment  *v1.Service `json:"service" bson:"service"`
}

type ListResp struct {
	Total int64      `json:"total"`
	Items []*Service `json:"items"`
}
